// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.spnetwork;

import java.nio.ByteBuffer;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import zombie.characters.IsoPlayer;
import zombie.core.network.ByteBufferWriter;

public final class UdpConnection {
    final UdpEngine engine;
    private final Lock bufferLock = new ReentrantLock();
    private final ByteBuffer bb = ByteBuffer.allocate(1000000);
    private final ByteBufferWriter bbw = new ByteBufferWriter(this.bb);
    public final IsoPlayer[] players;

    public UdpConnection(UdpEngine _engine) {
        this.players = IsoPlayer.players;
        this.engine = _engine;
    }

    public boolean ReleventTo(float x, float y) {
        return true;
    }

    public ByteBufferWriter startPacket() {
        this.bufferLock.lock();
        this.bb.clear();
        return this.bbw;
    }

    public void endPacketImmediate() {
        this.bb.flip();
        this.engine.Send(this.bb);
        this.bufferLock.unlock();
    }

    public void cancelPacket() {
        this.bufferLock.unlock();
    }
}
